package org.example.core.valid.annontation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 小杰_cc
 * @version 1.0
 */
public class ListValueConstrainValidator implements ConstraintValidator<ListValue,Integer> {
    private Set<Integer> set =  new HashSet<>();


    @Override
    public void initialize(ListValue constraintAnnotation) {
        int [] value = constraintAnnotation.value();
        for(int val : value){
            set.add(val);
        }
    }

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(integer);
    }
}
